<template>
  <div class="expert-page">
    <van-nav-bar
      :title="t('service.expert.title')"
      left-arrow
      @click-left="onClickLeft"
    >
      <template #right>
        <van-icon name="question-o" size="20" />
      </template>
    </van-nav-bar>
    
    <!-- 顶部横幅 -->
    <div class="expert-banner">
      <div class="banner-content">
        <div class="banner-icon">
          <van-icon name="service-o" size="40" />
        </div>
        <div class="banner-text">
          <div class="banner-title">{{ t('service.expert.teamTitle') }}</div>
          <div class="banner-desc">{{ t('service.expert.teamDesc') }}</div>
        </div>
      </div>
    </div>

    <div class="page-content">
      <!-- 联系方式卡片 -->
      <div class="section-title">{{ t('service.expert.contactTitle') }}</div>
      <div class="contact-grid">
        <div 
          v-for="(contact, index) in contactMethods" 
          :key="index"
          class="contact-card"
          @click="contact.action"
        >
          <div class="contact-icon" :class="contact.class">
            <van-icon :name="contact.icon" size="28" />
          </div>
          <div class="contact-title">{{ contact.title }}</div>
          <div class="contact-value">{{ contact.desc }}</div>
        </div>
      </div>

      <!-- 服务时间 -->
      <div class="section-title">{{ t('service.expert.serviceTimeTitle') }}</div>
      <div class="service-time-card">
        <div class="time-item">
          <div class="time-icon primary">
            <van-icon name="clock-o" size="20" />
          </div>
          <div class="time-info">
            <div class="time-label">{{ t('service.expert.onlineServiceTitle') }}</div>
            <div class="time-value">{{ t('service.expert.onlineServiceDesc') }}</div>
          </div>
        </div>
        
        <div class="time-item">
          <div class="time-icon success">
            <van-icon name="phone-o" size="20" />
          </div>
          <div class="time-info">
            <div class="time-label">{{ t('service.expert.phoneServiceTitle') }}</div>
            <div class="time-value">{{ t('service.expert.phoneServiceDesc') }}</div>
          </div>
        </div>
      </div>
    </div>

    <!-- 底部按钮 -->
    <div class="action-buttons">
      <van-button type="primary" block @click="onCallService">
        <van-icon name="phone-o" />
        <span>{{ currentLang === 'zh' ? '电话客服' : 'Call Service' }}</span>
      </van-button>
      <van-button type="success" block @click="onOnlineChat">
        <van-icon name="chat-o" />
        <span>{{ currentLang === 'zh' ? 'AI智能客服' : 'AI Support' }}</span>
      </van-button>
    </div>
  </div>
</template>

<script setup>
import { onMounted } from 'vue'
import { showToast, showLoadingToast, closeToast } from 'vant'
import { useI18n } from 'vue-i18n'
import { useRoute, useRouter } from 'vue-router'
import { getStoredLanguage } from '../../utils/language'
import { initZendesk, openZendeskChat } from '../../utils/zendesk'

const { t } = useI18n()
const router = useRouter()
const route = useRoute()

const currentLang = route.query.lang || getStoredLanguage()

// 返回上一页
const onClickLeft = () => {
  router.push({
    path: '/service',
    query: { lang: currentLang }
  })
}

// 拨打电话
const onCallService = () => {
  window.location.href = 'tel:010-1132546'
}

// 打开Zendesk在线客服
const onOnlineChat = async () => {
  // 显示加载提示
  showLoadingToast({
    message: currentLang === 'zh' ? '正在连接客服...' : 'Connecting...',
    forbidClick: true,
    duration: 0
  })
  
  // 打开Zendesk聊天窗口
  const success = await openZendeskChat()
  
  closeToast()
  
  if (!success) {
    showToast(currentLang === 'zh' ? '客服系统加载失败，请稍后重试' : 'Failed to load support system')
  }
}

// 联系方式列表
const contactMethods = [
  {
    icon: 'service-o',
    title: currentLang === 'zh' ? 'AI智能客服' : 'AI Support',
    desc: currentLang === 'zh' ? '即时响应' : 'Instant',
    class: 'ai-bot',
    action: onOnlineChat
  },
  {
    icon: 'chat-o',
    title: t('service.expert.qqTitle'),
    desc: t('service.expert.qqDesc'),
    class: 'qq',
    action: () => {
      showToast(currentLang === 'zh' ? '正在跳转QQ客服...' : 'Redirecting to QQ support...')
    }
  },
  {
    icon: 'wechat',
    title: t('service.expert.wechatTitle'),
    desc: t('service.expert.wechatDesc'),
    class: 'wechat',
    action: () => {
      showToast(currentLang === 'zh' ? '正在跳转微信客服...' : 'Redirecting to WeChat support...')
    }
  }
]

// 初始化Zendesk Widget
onMounted(async () => {
  await initZendesk({ 
    lang: currentLang
  })
})
</script>

<style scoped lang="scss">
.expert-page {
  min-height: 100vh;
  background: linear-gradient(180deg, #f0f9ff 0%, #f7f8fa 100%);
  padding-bottom: 80px;
}

// 顶部横幅
.expert-banner {
  background: linear-gradient(135deg, #1989fa 0%, #0e6fd6 100%);
  margin: 16px;
  padding: 28px 24px;
  border-radius: 16px;
  box-shadow: 0 8px 24px rgba(25, 137, 250, 0.4);
  animation: fadeInDown 0.5s ease-out;
}

@keyframes fadeInDown {
  from {
    opacity: 0;
    transform: translateY(-20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.banner-content {
  display: flex;
  align-items: center;
  color: #fff;
}

.banner-icon {
  width: 64px;
  height: 64px;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-right: 20px;
  animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.05);
  }
}

.banner-text {
  flex: 1;
}

.banner-title {
  font-size: 22px;
  font-weight: 600;
  margin-bottom: 8px;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.banner-desc {
  font-size: 14px;
  opacity: 0.95;
}

.page-content {
  padding: 0 16px;
}

// 标题
.section-title {
  font-size: 17px;
  font-weight: 600;
  color: #323233;
  margin: 20px 0 12px;
  position: relative;
  padding-left: 12px;
  
  &::before {
    content: '';
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 4px;
    height: 18px;
    background: linear-gradient(135deg, #1989fa 0%, #0e6fd6 100%);
    border-radius: 2px;
  }
}

// 联系方式网格
.contact-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-bottom: 20px;
}

.contact-card {
  background: #fff;
  border-radius: 12px;
  padding: 20px 12px;
  text-align: center;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
  transition: all 0.3s;
  cursor: pointer;
  animation: scaleIn 0.5s ease-out;
  
  &:active {
    transform: translateY(2px);
    box-shadow: 0 1px 6px rgba(0, 0, 0, 0.08);
  }
}

@keyframes scaleIn {
  from {
    opacity: 0;
    transform: scale(0.9);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

.contact-icon {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 12px;
  color: #fff;
  
  &.ai-bot {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
    animation: glow 2s ease-in-out infinite;
  }
  
  &.phone {
    background: linear-gradient(135deg, #1989fa 0%, #0e6fd6 100%);
    box-shadow: 0 4px 12px rgba(25, 137, 250, 0.3);
  }
  
  &.qq {
    background: linear-gradient(135deg, #07c160 0%, #05a050 100%);
    box-shadow: 0 4px 12px rgba(7, 193, 96, 0.3);
  }
  
  &.wechat {
    background: linear-gradient(135deg, #ff976a 0%, #ff7544 100%);
    box-shadow: 0 4px 12px rgba(255, 151, 106, 0.3);
  }
}

@keyframes glow {
  0%, 100% {
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
  }
  50% {
    box-shadow: 0 4px 20px rgba(102, 126, 234, 0.6);
  }
}

.contact-title {
  font-size: 14px;
  font-weight: 600;
  color: #323233;
  margin-bottom: 4px;
}

.contact-value {
  font-size: 12px;
  color: #969799;
}

// 服务时间卡片
.service-time-card {
  background: #fff;
  border-radius: 12px;
  padding: 20px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
}

.time-item {
  display: flex;
  align-items: flex-start;
  margin-bottom: 16px;
  
  &:last-child {
    margin-bottom: 0;
  }
}

.time-icon {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-right: 12px;
  flex-shrink: 0;
  
  &.primary {
    background: linear-gradient(135deg, #f0f9ff 0%, #e6f7ff 100%);
    color: #1989fa;
  }
  
  &.success {
    background: linear-gradient(135deg, #f0fdf4 0%, #dcfce7 100%);
    color: #07c160;
  }
}

.time-info {
  flex: 1;
}

.time-label {
  font-size: 15px;
  font-weight: 600;
  color: #323233;
  margin-bottom: 6px;
}

.time-value {
  font-size: 13px;
  color: #969799;
  line-height: 1.6;
  white-space: pre-line;
}

// 底部按钮
.action-buttons {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 12px 16px;
  background: #fff;
  box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.08);
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  z-index: 100;
  
  .van-button {
    height: 44px;
    border-radius: 22px;
    font-size: 15px;
    font-weight: 500;
    transition: all 0.3s;
    
    .van-icon {
      margin-right: 6px;
      font-size: 18px;
    }
    
    &:active {
      transform: scale(0.96);
    }
  }
}
</style>
